package com.ooobgy;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintStream;

public class EyeHunterSQLmaker {
	private String src;
	private String dist;
	private int packId;
	private PrintStream out;
	private BufferedReader in;

	public EyeHunterSQLmaker(String src, String dist, int packId)
			throws Exception {
		super();
		this.src = src;
		this.dist = dist;
		this.packId = packId;
		in = new BufferedReader(new FileReader(new File(src)));
		out = new PrintStream(new File(dist));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		if (args.length != 3) {
			System.out
					.println("Usage: EyeHunterSQLmaker [src] [dist] [packId]");
			return;
		}
		String src = args[0];
		String dist = args[1];
		try {
			int packId = Integer.parseInt(args[2]);
			EyeHunterSQLmaker sqLmaker = new EyeHunterSQLmaker(src, dist,
					packId);
			sqLmaker.make_sqlFile();
		} catch (Exception e) {
			System.err.println("file system error!");
			e.printStackTrace();
		}

	}

	public void make_sqlFile() throws Exception {
		String line = "";
		while ((line = in.readLine()) != null) {
			String[] items = line.split(";");
			String outLine = "insert into pic_target(mid,dust_pic,light_pic,min_x,min_y,max_x,max_y)";
			out.println(outLine);
			outLine = "   values(" + packId + ",'"+ items[1] +"','"+ items[0] + "'," +
							 "" + items[4] + "," + items[5] + "," + items[6] + "," + items[7] + ");";
			out.println(outLine);
		}
	}

	public String getSrc() {
		return src;
	}

	public void setSrc(String src) {
		this.src = src;
	}

	public String getDist() {
		return dist;
	}

	public void setDist(String dist) {
		this.dist = dist;
	}

	public int getPackId() {
		return packId;
	}

	public void setPackId(int packId) {
		this.packId = packId;
	}

}
